package eco2automotive.tasks;
import eco2automotive.port.ConnectionControl;
import eco2automotive.gui.components.Panel_TxRx;
/**  
 *  Sleep 1" and update the Panel_TxRx used by the app for display the data arrival.
  * @version 1.0
  * @autor Fco. Javier Sánchez Esparza
  *@see eco2automotive.gui.components.Panel_TxRx
  */ 
public class Thread_app extends Thread{
   private boolean next = true; //continue
   ConnectionControl connControl;
   Panel_TxRx PANEL_TXRX;
   /**
     * Start the thread and @param connControl send the data 
     * @param connControl connection active object
     * @param PANEL_TXRX display the RX data.     
     */ 
   public Thread_app(ConnectionControl connControl, Panel_TxRx PANEL_TXRX){
    this.connControl=connControl;
    this.PANEL_TXRX=PANEL_TXRX;
    }
   /**
    * Stop the thread
    */
   public void stop_Thread(){next=false;}
     /**
      * Resume the thread
      */
     public void resume_Thread(){next=true;}
   
   public void run()
   {               
       while(next){           
    try{this.sleep(1000);}catch(Exception e){}          
          String data="";      
          if((this.connControl!=null))              
              if(connControl.DATA_AVAILABLE()){                                 
                    data=connControl.getRXinfo();
                    System.out.println("DATA AVAILABLE?? "+data);                  
                    this.PANEL_TXRX.updateRX_INFO(data);                                                                                
                    this.PANEL_TXRX.updateTX_INFO(connControl.getTXinfo());
                                  }      

                }
        }
   }